package com.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.demo.dto.LoginDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

@RestController
@RequestMapping("/test")
public class TestController {

    private static Logger logger = LoggerFactory.getLogger(TestController.class);

    @PostMapping("/session")
    public String session(@RequestBody LoginDto loginDto){
        logger.info("/session,loginDto={}", loginDto);
        JSONObject jsonObject = new JSONObject();
        RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
        String sessionId = requestAttributes.getSessionId();
        jsonObject.put("code", "0");
        jsonObject.put("msg", "成功");
        jsonObject.put("sessionId", sessionId);
        logger.info("json={}", jsonObject);
        return jsonObject.toString();
    }
}
